//
//  CJBrowseListController.m
//  Boss
//
//  Created by admin on 2018/9/22.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJBrowseListController.h"
#import "CJCommissionCell.h"
#import "CJCommissionModel.h"
#import "CJBrowseListModel.h"
@interface CJBrowseListController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *listArray;

@property (nonatomic)NSUInteger page;
@end

@implementation CJBrowseListController
-(NSMutableArray *)listArray
{
    if (!_listArray) {
        _listArray = [[NSMutableArray alloc]init];
    }
    return _listArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.page = 1;
    [self setupUI];
    [self loadData];
    // Do any additional setup after loading the view.
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getBrowseListWithBusinessId:self.businessId WithCurrentPage:@"1" SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
       
        if (success) {
            [weakSelf.listArray addObjectsFromArray:[CJBrowseListModel getBrowseListModelFromJson:response[@"result"][@"detail"]]] ;
            [weakSelf.tableView reloadData];
        }
        
        
    }];
    
}

-(void)setupUI
{
    self.navigationItem.title = @"围观BOSS";
    [self.view addSubview:self.tableView];
    self.tableView.estimatedSectionHeaderHeight = 270;
    self.tableView.rowHeight = 73;
    [self.tableView registerNib:[UINib nibWithNibName:@"CJCommissionCell" bundle:nil] forCellReuseIdentifier:@"CJCommissionCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CJCommissionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CJCommissionCell" forIndexPath:indexPath];
    
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"CJCommissionRankCell" owner:nil options:nil].firstObject;
    }
    CJBrowseListModel *model = self.listArray[indexPath.row];
    [cell setListModel:model];
    //[cell setModel:model];
    //  cell.rankLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+1];
    return cell;
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
